package com.test.exam.dao;

import java.util.HashMap;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.test.exam.commons.PageHelper;
import com.test.exam.domain.Student;

@Repository
public class StudentDao {
	private final String STUDENT_NS = 
			"com.test.exam.mapper.StudentMapper";
	
	@Autowired 
	private SqlSessionTemplate sqlSessionTemplate;
	
	// 한 반의 학생목록
	public List<Student> getStudentsByBanIdx(int banIdx){
		return sqlSessionTemplate.selectList(
				STUDENT_NS+".getStudentsByBanIdx", banIdx);
	}
	
	// 전체 학생 row수
	public int getStudentCountByBanIdx(int banIdx){
		HashMap map = new HashMap();
		map.put("banIdx", banIdx);
		return sqlSessionTemplate.selectOne(
				STUDENT_NS+".getStudentCountByBanIdx", map);
	}
	
	// 조건 페이지  학생목록
	public List<HashMap> getStudentsByCurrentPage(
							int banIdx,
							PageHelper pageHelper){
		
		HashMap map = new HashMap();
		map.put("banIdx", banIdx);
		map.put("pageHelper", pageHelper);
		
		return sqlSessionTemplate.selectList(
				STUDENT_NS+".getAllStudentsByCurrentPage", map);
	}
	
	public int addStudent(Student student){
		return sqlSessionTemplate.insert(
				STUDENT_NS+".addStudent", student);
	}
}














